package com.xuhuan.juc.transfer;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author huan.xu
 * @Date 2021/12/30 22:40
 * @Description 值传递和引用传递
 */
@Slf4j
public class TransferValue {

    public void changeValue1(int age) {
        age = 30;
    }

    public void changeValue2(Person person) {
        person.setPersonName("xxx");
    }

    public void changeValue3(String personName) {
        personName = "xxx";
    }

    public static void main(String[] args) {
        TransferValue transferValue = new TransferValue();
        int age = 20;
        transferValue.changeValue1(age);
        log.info("age:{}", age);

        Person person = new Person("abc");
        transferValue.changeValue2(person);
        log.info("person.personName:{}", person.getPersonName());

        String str = "abc";
        transferValue.changeValue3(str);
        log.info("str:{}", str);

    }
}

@Data
class Person {
    private String personName;

    public Person(String personName) {
        this.personName = personName;
    }
}
